package net.starwifi.duobao.web.shop;

import net.starwifi.duobao.dto.JXDTO;
import net.starwifi.duobao.entity.Member;
import net.starwifi.duobao.mvc.*;
import net.starwifi.duobao.service.MemberService;
import net.starwifi.duobao.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

/**
 * Created by Administrator on 2015/11/9.
 */
@Controller("shopBrandController")
@RequestMapping(value = "/shop")
public class BrandController extends BaseController {


    /** 用户/商家 */
    @Autowired
    MemberService memberService;

    /** 商品 */
    @Autowired
    ProductService productService;

    /**
     * 店铺商品页
     */
    @RequestMapping(value = "/brand-{id}", method = RequestMethod.GET)
    public String brand(@PathVariable Long id,PageView pageView,Model model) {
        Member member=memberService.find(id);
        pageView.addFilter(Filter.eq("shopId",member.getId()));
        model.addAttribute("member",member);
        model.addAttribute("page",productService.getScrollData(pageView));
        return "/shop/brand";
    }

    /**
     * 店铺商品页
     */
    @ResponseBody
    @RequestMapping(value = "/brand-{id}/more", method = RequestMethod.GET)
    public Object more(@PathVariable Long id,PageView pageView,Model model) {
        pageView.addFilter(Filter.eq("isMarketable", Boolean.TRUE));
        pageView.addFilter(Filter.eq("memberType", 1)); //商家用户
        pageView.addFilter(Filter.eq("id", id)); //商家用户
        pageView.addOrder(Order.desc("id"));
        final Page page=memberService.getScrollData(pageView);
        return Message.createMessage(Message.success("success"), new HashMap<String, Object>() {{
            put("list", JXDTO.getList(page.getContent()));
        }});
    }




}
